import _WechatDelegate from "./CCWechatDelegate";

/*[*/export default/*]*/ class CCWechatNative
{
    //初始化微信平台
    public static Go(appId:string,universalLink:string)
    {
        if(!cc.sys.isNative) return

        if(cc.sys.os==cc.sys.OS_ANDROID)
        {
            console.log("=====call droid CCWechatNative Go")
            jsb.reflection.callStaticMethod(
                "org/cocos2dx/javascript/CCWechat", 
                "go", 
                "(Ljava/lang/String;Ljava/lang/String;)V", 
                appId,
                universalLink
            );
            
        } else if(cc.sys.os==cc.sys.OS_IOS){
            console.log("=====call ios CCWechatNative Go")
            jsb.reflection.callStaticMethod(
                "CCWechat",
                "go:universalLink:",
                appId,
                universalLink
            );
        }
        else
        {
            console.log("CCWechatNative.Go =======",appId,universalLink)
        }
    }


    //登录
    //obj = {
    //    success({code:string})
    //    fail({errCode:number})
    //}
    public static Login(obj)
    {
        if(!cc.sys.isNative) return
        
        //检查超时
        
        _WechatDelegate.onLoginCallbaks.CheckOvertime("fail",100)

        //加入回调队列
        obj.overtime = 60*1000*5
        _WechatDelegate.onLoginCallbaks.Add(obj)


        if(cc.sys.os==cc.sys.OS_ANDROID)
        {
            console.log("=====call droid CCWechatNative Login")
            jsb.reflection.callStaticMethod(
                "org/cocos2dx/javascript/CCWechat", 
                "login", 
                "()V" 
            );
        } else if(cc.sys.os==cc.sys.OS_IOS){
            console.log("=====call ios CCWechatNative Login")
            jsb.reflection.callStaticMethod(
                "CCWechat",
                "login"
            );
        }
        else
        {
            console.log("CCWechatNative.Login =======")
        }
    }
}